#include "data-bus.h"
#include "exceptions.h"

DataBusMember::DataBusMember (uint16_t address_base)
{
  _address_base = address_base;
  _next = 0;
}

void DataBusMember::attach_member (DataBusMember& bus, DataBusMember& member)
{
  member._next = 0;

  DataBusMember* cur = &bus;
  while (cur->_next != 0)
    cur = cur->_next;

  cur->_next = &member;
}

uint8_t DataBusMember::read (uint16_t address)
{
  if (_next != 0)
    return _next->read (address);
  else
    throw MemoryException (address);
}

void DataBusMember::write (uint16_t address, uint8_t data)
{
  if (_next != 0)
    _next->write (address, data);
}
